import sys
import os


if __name__ == '__main__':

    # 独立使用django的model
    pwd = os.path.dirname(os.path.realpath(__file__))
    sys.path.append(pwd + ".../")
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "FreshSupermarket.settings")

    import django

    django.setup()
    from goods.models import GoodsCategory, Goods, GoodsImage

    data = Goods.objects.all()
    print(len(data))
    
    '''
    from django.db.models import Q
all_goods = Goods.objects.all()
all_goods1 = all_goods.filter(shop_price__gte=150)
all_goods1  # 获取到价格高于150的所有商品
<QuerySet [<Goods: 新鲜水果甜蜜香脆单果约800克>, <Goods: 酣畅家庭菲力牛排10片澳洲生鲜牛肉团购套餐>, <Goods: 潮香村澳洲进口牛排家庭团购套餐20片>, <Goods: 爱食派内蒙古呼伦贝尔冷冻生鲜牛腱子肉1000g>, <Goods: 澳洲进口牛尾巴300g新鲜肥牛肉>, <Goods: 53度茅台仁酒500ml>, <Goods: 新西兰进口全脂奶粉900g>, <Goods: 维纳斯橄榄菜籽油5L/桶>]>
all_goods1.filter(category_id=122)  # 这是个二级分类
<QuerySet [<Goods: 澳洲进口牛尾巴300g新鲜肥牛肉>]>
all_goods1.filter(category__parent_category_id=122)
<QuerySet []>
all_goods1.filter(Q(category_id=122)|Q(category__parent_category_id=122))
<QuerySet [<Goods: 澳洲进口牛尾巴300g新鲜肥牛肉>]>
    '''